<?php
/**
 * Created by PhpStorm.
 * User: zhaoye
 * Date: 16/7/15
 * Time: 下午3:58
 */

namespace controller\Api;

use ZPHP\Core\Db;
use tool\M2Result;
use model\Member;
use tool\Validation;
use ZPHP\Core\Log;

class CMember extends Base{

    public function init()
    {
        return parent::init();
    }

    /**
     * 注册
     * @return string
     */
    public function login()
    {
        $params = $this->request->raw;
        $params = json_decode($params,true);
        $m2_result = new M2Result();
        $model = new Member();
        $data = yield $model->login($params);
        if($data === false)
        {
            $m2_result->code = $model->code;
            $m2_result->msg = $model->msg;

        }
        return $m2_result->toJson();
    }

    /**
     * 注册
     * @return string
     */
    public function reg()
    {
        $params = $this->request->raw;
        $params = json_decode($params,true);
        $m2_result = new M2Result();
        $model = new Member();
        $data = yield $model->reg($params);
        if($data === false)
        {
            $m2_result->code = $model->code;
            $m2_result->msg = $model->msg;
            $data = '';

        }
        $m2_result->data = $data;
        return $m2_result->toJson();
    }

    /**
     * 批量注册
     * @return string
     */
    public function regs()
    {
        $params = $this->request->raw;
        $params = json_decode($params,true);
        $m2_result = new M2Result();
        $model = new Member();
        $data = yield $model->regs($params);
        if($data !== true)
        {
            $m2_result->code = $model->code;
            $m2_result->msg = $model->msg;
            $m2_result->errordata = $data;
        }
        return $m2_result->toJson();
    }
    /**
     * 重置密码
     * @return string
     */
    public function resetPassword()
    {
        $params = $this->request->raw;
        $params = json_decode($params,true);
        $m2_result = new M2Result();
        $model = new Member();
        $data = yield $model->resetPassword($params);
        if($data === false)
        {
            $m2_result->code = $model->code;
            $m2_result->msg = $model->msg;
        }
        return $m2_result->toJson();
    }

    /**
     * 获取单个用户
     * @return string
     */
    public function getUser()
    {
        $params = $this->request->raw;
        $params = json_decode($params,true);
        $m2_result = new M2Result();
        $model = new Member();
        $data = yield $model->getUser($params);
        if($data === false)
        {
            $m2_result->code = $model->code;
            $m2_result->msg = $model->msg;
            $data = '';

        }
        $m2_result->data = $data;
        return $m2_result->toJson();
    }

    /**
     * 获取用户
     * @return string
     */
    public function getUsers()
    {
        $params = $this->request->raw;
        $params = json_decode($params,true);
        $m2_result = new M2Result();
        $model = new Member();
        $data = yield $model->getUsers($params);
        if($data === false)
        {
            $m2_result->code = $model->code;
            $m2_result->msg = $model->msg;
            $data = '';

        }
        $m2_result->data = $data;
        return $m2_result->toJson();
    }

    /**
     * 删除用户
     * @return string
     */
    public function deleteUser()
    {
        $params = $this->request->raw;
        $params = json_decode($params,true);
        $m2_result = new M2Result();
        $model = new Member();
        $data = yield $model->deleteUser($params);
        if($data === false)
        {
            $m2_result->code = $model->code;
            $m2_result->msg = $model->msg;

        }
        return $m2_result->toJson();
    }

    /**
     * 删除用户
     * @return string
     */
    public function deleteUsers()
    {
        $params = $this->request->raw;
        $params = json_decode($params,true);
        $m2_result = new M2Result();
        $model = new Member();
        $data = yield $model->deleteUsers($params);
        if($data !== true)
        {
            $m2_result->code = $model->code;
            $m2_result->msg = $model->msg;
            $m2_result->errordata = $data;
        }
        return $m2_result->toJson();
    }

    /**
     * 修改昵称
     * @return string
     */
    public function editNickname()
    {
        $params = $this->request->raw;
        $params = json_decode($params,true);
        $m2_result = new M2Result();
        $model = new Member();
        $data = yield $model->editNickname($params);
        if($data === false)
        {
            $m2_result->code = $model->code;
            $m2_result->msg = $model->msg;
        }
        return $m2_result->toJson();
    }

    /**
     * 添加好友
     * @return string
     */
    public function addFriend()
    {
        $params = $this->request->raw;
        $params = json_decode($params,true);
        $m2_result = new M2Result();
        $model = new Member();
        $data = yield $model->addFriend($params);
        if($data === false)
        {
            $m2_result->code = $model->code;
            $m2_result->msg = $model->msg;
        }
        return $m2_result->toJson();
    }

    /**
     * 删除好友
     * @return string
     */
    public function deleteFriend()
    {
        $params = $this->request->raw;
        $params = json_decode($params,true);
        $m2_result = new M2Result();
        $model = new Member();
        $data = yield $model->deleteFriend($params);
        if($data === false)
        {
            $m2_result->code = $model->code;
            $m2_result->msg = $model->msg;
        }
        return $m2_result->toJson();
    }

    /**
     * 查看好友
     * @return string
     */
    public function showFriends()
    {
        $params = $this->request->raw;
        $params = json_decode($params,true);
        $m2_result = new M2Result();
        $model = new Member();
        $data = yield $model->showFriends($params);
        if($data === false)
        {
            $m2_result->code = $model->code;
            $m2_result->msg = $model->msg;
            $data = '';
        }
        $m2_result->data = $data;
        return $m2_result->toJson();
    }

    /**
     * 查看好友
     * @return string
     */
    public function getBlacklist()
    {
        $params = $this->request->raw;
        $params = json_decode($params,true);
        $m2_result = new M2Result();
        $model = new Member();
        $data = yield $model->getBlacklist($params);
        if($data === false)
        {
            $m2_result->code = $model->code;
            $m2_result->msg = $model->msg;
            $data = '';
        }
        $m2_result->data = $data;
        return $m2_result->toJson();
    }

    /**
     * 往黑名单中加人
     * @return string
     */
    public function addUserForBlacklist()
    {
        $params = $this->request->raw;
        $params = json_decode($params,true);
        $m2_result = new M2Result();
        $model = new Member();
        $data = yield $model->addUserForBlacklist($params);
        if($data === false)
        {
            $m2_result->code = $model->code;
            $m2_result->msg = $model->msg;
            $data = '';
        }
        $m2_result->data = $data;
        return $m2_result->toJson();
    }
    /**
     * 从黑名单中减人
     * @return string
     */
    public function deleteUserFromBlacklist()
    {
        $params = $this->request->raw;
        $params = json_decode($params,true);
        $m2_result = new M2Result();
        $model = new Member();
        $data = yield $model->deleteUserFromBlacklist($params);
        if($data === false)
        {
            $m2_result->code = $model->code;
            $m2_result->msg = $model->msg;
            $data = '';
        }
        $m2_result->data = $data;
        return $m2_result->toJson();
    }

    /**
     * 查看用户是否在线
     * @return string
     */
    public function isOnline()
    {
        $params = $this->request->raw;
        $params = json_decode($params,true);
        $m2_result = new M2Result();
        $model = new Member();
        $data = yield $model->isOnline($params);
        if($data === false)
        {
            $m2_result->code = $model->code;
            $m2_result->msg = $model->msg;
            $data = '';
        }
        $m2_result->data = $data;
        return $m2_result->toJson();
    }

    /**
     * 查看用户离线消息数
     * @return string
     */
    public function getOfflineMessages()
    {
        $params = $this->request->raw;
        $params = json_decode($params,true);
        $m2_result = new M2Result();
        $model = new Member();
        $data = yield $model->getOfflineMessages($params);
        if($data === false)
        {
            $m2_result->code = $model->code;
            $m2_result->msg = $model->msg;
            $data = '';
        }
        $m2_result->data = $data;
        return $m2_result->toJson();
    }

    /**
     * 禁用用户账号
     * @return string
     */
    public function deactiveUser()
    {
        $params = $this->request->raw;
        $params = json_decode($params,true);
        $m2_result = new M2Result();
        $model = new Member();
        $data = yield $model->deactiveUser($params);
        if($data === false)
        {
            $m2_result->code = $model->code;
            $m2_result->msg = $model->msg;
            $data = '';
        }
        $m2_result->data = $data;
        return $m2_result->toJson();
    }

    /**
     * 解禁用户账号
     * @return string
     */
    public function activeUser()
    {
        $params = $this->request->raw;
        $params = json_decode($params,true);
        $m2_result = new M2Result();
        $model = new Member();
        $data = yield $model->activeUser($params);
        if($data === false)
        {
            $m2_result->code = $model->code;
            $m2_result->msg = $model->msg;
            $data = '';
        }
        $m2_result->data = $data;
        return $m2_result->toJson();
    }

    /**
     * 强制用户下线
     * @return string
     */
    public function disconnectUser()
    {
        $params = $this->request->raw;
        $params = json_decode($params,true);
        $m2_result = new M2Result();
        $model = new Member();
        $data = yield $model->disconnectUser($params);
        if($data === false)
        {
            $m2_result->code = $model->code;
            $m2_result->msg = $model->msg;
            $data = '';
        }
        $m2_result->data = $data;
        return $m2_result->toJson();
    }

}
